angular.module('crawlerApp')
.controller('groupSetCtr', ['$scope', function($scope){
  $scope.controllerName = 'groupSetCtr';
  $scope.title = '分组管理';
  $scope.group = {
    'name': '分组一',
    'projects': []
  }
  $scope.projects = [{
      'name': '项目1'
    }, {
      'name': '项目2'
    }, {
      'name': '项目3'
    }, {
      'name': '项目4'
    }, {
      'name': '项目5'
    }
  ]
  $scope.moveUp = function(project) {
    angular.forEach($scope.group.projects, function(prj, key) {
      if (angular.equals(prj, project)) {
        if (key == 0) {
          return ;
        }else{
          $scope.group.projects.splice(key, 1)
          $scope.group.projects.splice(key-1, 0,project)
        }
        // $scope.group.projects.splice(key, 1)
      };
    });
    // alert('moveUp')
  }
  $scope.moveDown = function(project) {
    angular.forEach($scope.group.projects, function(prj, key) {
      if (angular.equals(prj, project)) {
        if (key == $scope.group.projects.length-1) {
          return ;
        }else{
          $scope.group.projects.splice(key, 1)
          $scope.group.projects.splice(key+1, 0,project)
        }
        // $scope.group.projects.splice(key, 1)
      };
    });
    // alert('moveDown')
  }
  $scope.showProject = function(project) {
    alert('showProject')
  }
  $scope.deleteProject = function(project) {
    angular.forEach($scope.group.projects, function(prj, key) {
      if (angular.equals(prj, project)) {
        $scope.group.projects.splice(key, 1)
      };
    });
    alert('deleteProject')
  }
  $scope.groupSetSave = function(task) {
    alert('groupSetSave')
  }
}])